<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.ico">
    <title>Preclinic - Medical & Hospital - Bootstrap 4 Admin Template</title>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <!--[if lt IE 9]>
		<script src="assets/js/html5shiv.min.js"></script>
		<script src="assets/js/respond.min.js"></script>
	<![endif]-->
</head>

<body>
    <div class="main-wrapper">
        <div class="page-wrapper" style="padding-top: 0px;">
            <div class="content">
                <div class="row">
                    <div class="col-sm-8">
                        <h4 class="page-title">角色和权限</h4>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-4 col-md-4 col-lg-4 col-xl-3">
                        <a href="add-role.html" class="btn btn-primary btn-block"><i class="fa fa-plus"></i> 添加角色</a>
                        <div class="roles-menu">
                            <ul id="roles">                                
                            </ul>
                        </div>
                    </div>
                    <div class="col-sm-8 col-md-8 col-lg-8 col-xl-9">
                        <h6 class="card-title m-b-20">可访问的模块</h6>
                        <div class="m-b-30">							
                            <ul class="list-group" id="modules">								
                            </ul>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped custom-table">
                                <thead>
                                    <tr>
                                        <th>模块权限</th>
                                        <th class="text-center">读Read</th>
                                        <th class="text-center">写Write</th>
                                        <th class="text-center">创建Create</th>
                                        <th class="text-center">删除Delete</th>
                                        <th class="text-center">导入Import</th>
                                        <th class="text-center">导出Export</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>员工</td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>假期</td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>请假</td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Events</td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                        <td class="text-center">
                                            <input type="checkbox" checked="">
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<div id="delete_role" class="modal fade delete-modal" role="dialog">
			<div class="modal-dialog modal-dialog-centered">
				<div class="modal-content">
					<div class="modal-body text-center">
						<img src="assets/img/logo-dark.png" alt="" width="50" height="46">
						<h3>Are you sure want to delete this Role?</h3>
						<div class="m-t-20"> <a href="#" class="btn btn-white" data-dismiss="modal">Close</a>
							<button type="submit" class="btn btn-danger">Delete</button>
						</div>
					</div>
				</div>
			</div>
		</div>
    </div>
    <div class="sidebar-overlay" data-reff=""></div>
    <script src="assets/js/jquery-3.2.1.min.js"></script>
	<script src="assets/js/popper.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>
    <script src="assets/js/app.js"></script>
	<!--json data-->
	<script type="text/javascript" src="js/data.js"></script>
	<script type="text/javascript" src="json/roles.json"></script>
	<script type="text/javascript" src="json/module.json"></script>
	<script type="text/javascript">		
				
		//角色
		var rolesStr = "";
		for(var i = 0; i < roles.length; i++){
			rolesStr = rolesStr + '<li class="">';
            rolesStr = rolesStr + '<a href="javascript:getModules(\''+roles[i].code+'\');">'+ roles[i].name + '(' + roles[i].code + ')</a>';
			rolesStr = rolesStr + '<span class="role-action">';
			rolesStr = rolesStr + '<a href="edit-role.html">';
			rolesStr = rolesStr + '<span class="action-circle large">';
			rolesStr = rolesStr + '<i class="material-icons">edit</i>';
			rolesStr = rolesStr + '</span>';
			rolesStr = rolesStr + '</a>';
			rolesStr = rolesStr + '<a href="#" data-toggle="modal" data-target="#delete_role">';
			rolesStr = rolesStr + '<span class="action-circle large delete-btn">';
			rolesStr = rolesStr + '<i class="material-icons">delete</i>';
			rolesStr = rolesStr + '</span>';
			rolesStr = rolesStr + '</a>';
			rolesStr = rolesStr + '</span>';
            rolesStr = rolesStr + '</li>';
		}
		$("#roles").html(rolesStr);
		
		//模块
		function getModules(role){
			var modulesStr = "";
			var modules = getData(this.modules, 'role=' + role);
			for(var i = 0; i < modules.length; i++){
				modulesStr = modulesStr + '<li class="list-group-item">' + modules[i].name;
				modulesStr = modulesStr + '<input name="id" type="hidden" value="'+modules[i].id+'">';
				modulesStr = modulesStr + '<input name="name" type="hidden" value="'+modules[i].name+'">';
				modulesStr = modulesStr + '<div class="material-switch float-right">';
				modulesStr = modulesStr + '<input name="visit" id="'+modules[i].id+'_module" type="checkbox"';
				if(modules[i].visit == "true"){
					modulesStr = modulesStr + 'checked="true"';
				}
				modulesStr = modulesStr + ' >';
				modulesStr = modulesStr + '<label for="'+modules[i].id+'_module" class="badge-success"></label>';
				modulesStr = modulesStr + '</div>';
				modulesStr = modulesStr + '</li>';			
			}
			$("#modules").html(modulesStr);
		}
		
		$(".roles-menu ul li").on('click', function (){
			//把其他的移除
			$(".roles-menu ul li").each(function (){
				$(this).removeClass("active");
			});
			//给当前添加
			$(this).addClass("active");
		});
	</script>
</body>

</html>